//
//  Functions.swift
//  EasyTrademarkRegqurySearch
//
//  Created by 伊伊 on 2024/2/28.
//

import Foundation
import UIKit


func kFont(_ fontSize:CGFloat) -> UIFont {
    return UIFont.systemFont(ofSize: fontSize)
}

func kMediumFont(_ fontSize:CGFloat) -> UIFont {
    return UIFont(name: "PingFangSC-Medium", size: fontSize)!
}

 func kRegularFont(ofSize fontSize: CGFloat) -> UIFont{
    return UIFont(name: "PingFangSC-Regular", size: fontSize)!
 }
 
func kSemiboldFont(_ fontSize:CGFloat) -> UIFont {
    return UIFont(name: "PingFangSC-Semibold", size: fontSize)!
}


func testPrint<T>(_ msg:T,file:NSString = #file,line:Int = #line,fn:String = #function) {
  
    #if DEBUG
    let preffix = "\(file.lastPathComponent): \(line)_\(fn)"
    print(preffix,msg)
    #endif
  
}




func isiPhoneXScreen() -> Bool {
    if #available(iOS 13.0, *) {
        let scene =  UIApplication.shared.connectedScenes.first
        if  let windowscene = scene as? UIWindowScene{
            let window = windowscene.windows.first
            return window?.safeAreaInsets.bottom ?? 0.0 > 0.0
        }else{
            return  false
        }
     }else{
        let isX = UIApplication.shared.delegate!.window!?.safeAreaInsets.bottom ?? 0.0 > 0.0
        return isX
    }
}


func kAscaleX(_ x:CGFloat) -> CGFloat {
    let w:CGFloat = 375.0
    
    return  UIScreen.main.bounds.size.width/w * x
}
func kAscaleY(_ y:CGFloat) -> CGFloat {
   return UIScreen.main.bounds.size.height/667 * y
}

extension UIFont{
    func scaleX(_ x:CGFloat) -> UIFont{
       return self.withSize(x * self.pointSize)
    }
}

func configure<T: AnyObject>(_ object: T, closure: (T) -> Void) -> T {
    closure(object)
    return object
}


